<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
    <style>
        body {
            font: 18px "Microsoft YaHei UI";
            margin: 0;
            background-color: #fafafa;
        }
        header, main, footer {
            padding-left: 0 !important;
            padding-right: 0 !important;
        }
        header a {
            text-decoration: none;
            color: #6c6c6c;
        }
        header a:hover {
            color: #0aa1ed;
        }
        .el-input__inner {
            padding-right: 35px;
        }
        /*销量排行榜表格间距*/
        .el-table .el-table__cell {
            padding: 0;
        }
        /*给图片添加阴影*/
        .item_div img:hover {
            position: relative;
            bottom: 5px;
            /*元素阴影: x偏移值 y偏移值 浓度 范围 颜色*/
            box-shadow: 0 0 12px 5px #333;
        }
        .el-main{
            overflow: hidden;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header>
            <div style="width: 1200px;margin: 0 auto">
                <img src="imgs/logo.png" style="width: 300px;vertical-align: middle" alt="">
                <span style="margin-left: 50px">
                    <a href="/" style="color: #0aa1ed">首页</a><el-divider direction="vertical"></el-divider>
                    <a href="">热点咨询</a><el-divider direction="vertical"></el-divider>
                    <a href="">社会招聘</a><el-divider direction="vertical"></el-divider>
                    <a href="">校园招聘</a><el-divider direction="vertical"></el-divider>
                    <a href="">帮助中心</a>
                </span>
            </div>
            <!--蓝条开始-->
            <div style="width: 100%;height:60px;background-color: #82c8ec">
                <el-menu style="width: 1200px;margin: 0 auto"

                         class="el-menu-demo"
                         mode="horizontal"
                         @select="handleSelect"
                         background-color="#82c8ec"
                         text-color="#fff"
                         active-text-color="#fff">
                    <el-menu-item v-for="c in categoryArr" :index="c.id">{{c.name}}</el-menu-item>
                    <el-menu-item style="float: right" index="-1">
                        <!--keydown.enter 添加回车按下事件-->
                        <el-input size="mini" v-model="wd" @keydown.native.enter="search()" placeholder="请输入关键字搜索"></el-input>
                    </el-menu-item>
                    <el-button
                            style="float: right;background-color: rgba(0,0,0,0);border:none;position: relative;top: 15px;left: 220px"
                            @click="search()"
                            icon="el-icon-search"></el-button>
                </el-menu>
            </div>
            <!--蓝条结束-->
        </el-header>
        <el-main style="width: 1200px;margin: 100px auto 0 auto">
            <el-row :gutter="20">
                <el-col :span="18">
                    <!--走马灯开始-->
                    <el-carousel trigger="click" height="300px">
                        <el-carousel-item v-for="b in bannerArr">
                            <img :src="b.url" style="width: 100%;height: 100%" alt="">
                        </el-carousel-item>
                    </el-carousel>
                    <!--走马灯结束-->
                </el-col>
                <el-col :span="6">
                    <el-card>
                        <h3><i style="font-weight: bold" class="el-icon-trophy"></i>销量最高</h3>
                        <el-divider></el-divider>
                        <!--销量排行榜开始-->
                        <el-table :data="topArr" style="width: 500px">
                            <!--type="index" 列的内容为序号-->
                            <el-table-column type="index" label="排名">
                            </el-table-column>
                            <el-table-column label="商品名">
                                <template slot-scope="scope">
                                    <a style="text-decoration: none;color: #333" :href="'/detail.html?id='+scope.row.id">
                                        {{scope.row.title}}</a>
                                </template>
                            </el-table-column>
                            <el-table-column prop="saleCount" label="销量">
                            </el-table-column>
                        </el-table>
                        <!--销量排行榜结束-->
                    </el-card>
                </el-col>
            </el-row>
            <!--商品列表开始-->
            <el-row :gutter="20">
                <el-col :span="6" v-for="p in productArr">
                    <el-card :body-style="{ padding: '0px' }">
                        <div class="item_div" style="padding: 20px 20px 0 20px">
                            <a :href="'/detail.html?id='+p.id">
                                <img :src="p.url" width="100%" height="243" class="image">
                            </a>
                        </div>
                        <div style="padding: 14px;">
                            <a :href="'/detail.html?id='+p.id" style="text-decoration: none;color: #333">
                                <p style="margin-top: 0;font-size: 15px;height: 38px">{{p.title}}</p>
                            </a>
                            <div class="bottom clearfix" style="color: #6c6c6c">
                <span>￥{{p.price}}
                  <small style="text-decoration: line-through">￥{{p.oldPrice}}</small></span>
                                <span style="float: right">销量:{{p.saleCount}}件</span>
                            </div>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
            <!--商品列表结束-->
        </el-main>
        <el-footer>
            <div style="background-image: url('imgs/wave.png');
    height: 95px;margin-bottom: -30px"></div>
            <div style="background-color: #3f3f3f;padding: 30px;
    text-align: center;color: #b1b1b1;font-size: 14px;height: 100px">
                <p>Copyright © 北京达内金桥科技有限公司版权所有 京ICP备12003709号-3 京公网安备 11010802029572号</p>
                <p>涵盖20余门课程体系，致力于打造权威的IT职业教育学习平台</p>
                <p>达内在线WWW.TMOOC.CN 专注于IT职业技能培训</p>
            </div>
        </el-footer>
    </el-container>

</div>
</body>
<script src="js/vue.min.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                wd: "",
                bannerArr: [],
                topArr: [{title: "小米12pro", saleCount: 876543},
                    {title: "华为手表", saleCount: 76543},
                    {title: "最生活毛巾", saleCount: 6543},
                    {title: "双飞燕鼠标", saleCount: 543},
                    {title: "耐克运动服", saleCount: 43},
                    {title: "苹果手机", saleCount: 3}],
                productArr: [],
                categoryArr: []
            }
        },
        methods: {
            handleSelect(index) {
                console.log(index);
                //传递过来的index 就是分类的id ;跳转到新的页面显示这个分类下的商品信息
                if (index!=-1){
                    location.href="/result.html?cid="+index;
                }
            },
            search(){
                //跳转到结果页面,并把搜索的关键字传递过去
                location.href = "/result.html?wd=" + v.wd;
            }
        },
        created: function () {
            //发请求获取所有的分类信息
            axios.get("/category/select").then(function (response) {
                v.categoryArr = response.data;
            })
            //发请求获取所有轮播图信息
            axios.get("/banner/select").then(function (response) {
                v.bannerArr = response.data;
            })
            //发请求获取所有商品信息
            axios.get("/product/select/index").then(function (response) {
                v.productArr = response.data;
            })
            //发请求获取排行榜数据
            axios.get("/product/select/top").then(function (response) {
                v.topArr = response.data;
            })
        }
    })
</script>
</html>